package com.study.webapp.leetcode;

import com.alibaba.fastjson.JSON;
import io.swagger.models.auth.In;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 数组全排列，回溯法
 */
public class Leet_46 {


    public static void main(String[] args) {
        int[] a = {3,2,1};
        System.out.println(permute(a));
    }

    public static List<List<Integer>> permute (int[] a) {
        List<List<Integer>> list = new ArrayList<>();
        List<Integer> integers = new ArrayList<>();

        backString(a,integers,list);
        return list;
    }

    private static void backString(int[] a, List<Integer> integers, List<List<Integer>> list) {
        if (a.length == integers.size()) {
            list.add(new ArrayList<>(integers));
            return;
        }
        for (int i = 0; i< a.length; i++) {
            if (integers.contains(a[i])) {
                continue;
            }
            integers.add(a[i]);
            backString(a,integers,list);
            integers.remove(integers.size() - 1);
        }
    }
}
